package async;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
import java.util.Queue;
import java.util.concurrent.Executor;

import com.google.protobuf.Message;

public class NonBlockingSender {

	private final Selector selector;
	
	//@Property
	private Executor executor;
	
	public NonBlockingSender() throws IOException {
		selector = Selector.open();
	}
	
	public void send(final SocketChannel socketChannel, ByteBuffer buffer) {
		executor.execute(new Runnable() {
			public void run() {
				SelectionKey key = socketChannel.keyFor(selector);
				Queue<Message> queue;
				if(key == null || !key.isValid() || !key.isWritable()) {
					socketChannel.register(selector, SelectionKey.OP_WRITE, );
				} else {
					queue = key.attachment();
				}
			}});
	}
	
	
	
}
